unit SRVR_MAIN;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.SvcMgr, Vcl.Dialogs,Modl_HTTP;

type
  TSRVRHYGL = class(TService)
    procedure ServiceStart(Sender: TService; var Started: Boolean);
    procedure ServiceStop(Sender: TService; var Stopped: Boolean);
    procedure ServiceShutdown(Sender: TService);
  private
    FIsRunning:Boolean;
  public
    function GetServiceController: TServiceController; override;
    procedure StartService;
    procedure StopService;
  end;

var
  SRVRHYGL: TSRVRHYGL;

const
  CONST_SRVR_NAME='SRVRHYGL';

implementation

{$R *.dfm}

procedure ServiceController(CtrlCode: DWord); stdcall;
begin
  SRVRHYGL.Controller(CtrlCode);
end;

function TSRVRHYGL.GetServiceController: TServiceController;
begin
  Result := ServiceController;
end;

procedure TSRVRHYGL.ServiceShutdown(Sender: TService);
begin
  StopService;
end;

procedure TSRVRHYGL.ServiceStart(Sender: TService; var Started: Boolean);
begin
  StartService;
  Started:=FIsRunning;
end;

procedure TSRVRHYGL.ServiceStop(Sender: TService; var Stopped: Boolean);
begin
  StopService;
  Stopped:=not FIsRunning;
end;

procedure TSRVRHYGL.StartService;
begin
  if not FIsRunning then
  begin
    ModlHttp.Start;
    FIsRunning := True;
  end;
end;

procedure TSRVRHYGL.StopService;
begin
  if FIsRunning then
  begin
    ModlHttp.Stop;
    FIsRunning := False;
  end;
end;

end.
